<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
	
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Iterator" %>

<%@ page import ="com.easyattendance.services.AddTeacherService" %>
<%@ page import ="com.easyattendance.model.Teacher" %>
<%@ page import ="com.easyattendance.services.AddClassService" %>
<%@ page import ="com.easyattendance.model.Class" %>
<%@ page import ="com.easyattendance.services.AddTeacherService" %>
<%@ page import ="com.easyattendance.model.Teacher" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Class Teacher - Add Subject</title>
<!-- <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> -->
<jsp:include page="../includeFiles.jsp" />

<body class="left-sidebar">

<!-- Session check : user logged in or not/ press back button -->
<jsp:include page="../common/checkSession.jsp"></jsp:include>
<jsp:include page="../common/checkTeacherRole.jsp" />

<% String currentUser = (String) session.getAttribute("currentUser"); 
	AddClassService addClassService = new AddClassService();
	// for below line to run the currentUser must be a class teacher - so filter is to b done on classTeacher views, etc
	Class tempClass = addClassService.getClassById(addClassService.getClassIdByTeacherId(currentUser)); %>
	<!-- Wrapper -->
	<div id="wrapper">

		<!-- Content -->
		<div id="content">
			<div id="content-inner">

				<!-- Login -->
						<div id="login_content">
						<header>
							<h2>Add Subject</h2>
						</header>
						<span class="error_msg">${null_values}</span>
						<span class="success_msg">${subjectAdded}</span>
						<span class="error_msg">${subjectNoAdded}</span>
						<div class="submit_errors_msg">
							<ul>
								<li id="submit_is_field_empty" class="submit_errors">All * fields are required.</li>
							</ul>
						</div>
						<form name="Add_Subject" action="${pageContext.request.contextPath}/AddSubjectServlet" method="post"  onsubmit="return checkFormErrors();">
							<input type="hidden" id="action_type" name="action_type" value="create">
							<!-- Category -->
							<div>
							
							<% int no = tempClass.getNo_of_electives();
							if(no == 0) {%>
									<label>Choose Elective Type: <span class="error_msg">*</span></label>
									<select tabindex="1" name="elective_select" id="elective_select">
											<option value='Not Elective'>Not Elective</option>
									</select>
							<% }else {%>
								<label>Choose Elective Type:</label>
								<select tabindex="1" name="elective_select" id="elective_select">
									<% for(int i=1; i <=tempClass.getNo_of_electives(); i++) { %>
											<% String val = "Elective_"+i; System.out.println("elec "+val);%>
											<option value="<%=val%>">Elective_<%= i%>
									<% } %>
										<option value='Not Elective'>Not Elective</option>
									</select>
							<% } %>
							</div>
							<!-- Subject Name -->
							<div>
								<label>Subject Name: <span class="error_msg">*</span></label>
								<input id="subject_name" name="subject_name" type="text" placeholder="Subject Name"  maxlength="32" tabindex="2">
							</div>
							<div id="name_error" class="error_info">
								<ul>
									<li id="name_empty" class="invalid">First name can't be empty.</li>
									<li id="name_length" class="invalid">Length must be between 2 to 32.</li>
									<li id="name_invalid" class="invalid">Only alphanumeric characters.</li>
								</ul>
							</div>
							
							<!-- Sem Year-->
							<%-- <div>
								<label>Choose Semester/Year:</label>
								<select tabindex="3" name="sem_year_select" id="sem_year_select">
									<option value="">Select Semester/Year
										<% AddClassService addClassService = new AddClassService();	
										List<Class> ClassList = new ArrayList<Class>();
										ClassList = addClassService.getClassIdByTeacherId(currentUser);
										Class tempClass = null;
										Iterator ClassItr = ClassList.iterator();
								
										while(ClassItr.hasNext()) { %>
											<% tempClass = (Class) ClassItr.next();
												String ClassName = tempClass.getSem_year_name();
												String ClassId = tempClass.getSem_year_id();%>
									<option value=ClassId><%= ClassName %>
									<% } %>
								</select>
							</div> --%>
							
							<!-- <!-- No of subject teachers
							<div>
								<label>No. of Subject Teachers:</label>
								<input id="no_teachers" name="no_teachers" type="number" placeholder="No. of Subject Teachers" maxlength="1" tabindex="7">
							</div>
							<div id="no_teachers_error" class="error_info">
								<ul>
									<li id="no_teacher_length" class="invalid">Length must be 1.</li>
								</ul>
							</div> -->
							
							<!-- Category -->
							<div>
								<label>Choose Subject Teacher: <span class="error_msg">*</span></label>
								<select name="teacher_select" id="teacher_select" multiple="multiple" size="2" tabindex="3">
									<option value="">Choose Subject Teacher
										<% AddTeacherService addTeacherService = new AddTeacherService();	
										List<Teacher> teacherList = new ArrayList<Teacher>();
										String deptId = addTeacherService.getSectionEmailIdByTeacherId(currentUser);
										teacherList = addTeacherService.listTeachers(deptId);
										Teacher tempTeacher = null;
										Iterator teacherItr = teacherList.iterator();
								
										while(teacherItr.hasNext()) { %>
											<% tempTeacher = (Teacher) teacherItr.next();
												String teacherName = tempTeacher.getTeacher_name()+" "+tempTeacher.getTeacher_lname();
												String teacherId = tempTeacher.getTeacher_id(); %>
									<option value=<%= teacherId%>><%= teacherName %>
									<% } %>
								</select>
							</div>		
							
							<!-- Foreign Keys :  Hidden Fields. -->
							<input name="class_id" type = "hidden" id="class_id" value=<%= tempClass.getClass_id() %>>
							<!-- <input name="teacher_name_selected" type = "hidden" id="teacher_name_selected"/> -->
							<input name="elective_selected" type = "hidden" id="elective_selected"/>					
							
							<div>	
								<input type="submit" value="Add Subject" class="button" tabindex="4">
							</div>
						</form>
					</div>
			
			</div>
		</div>

		<!-- Sidebar -->
		<div id="sidebar">

			<!-- Sidebar Header - Logo & Name -->
			<jsp:include page="../common/sidebarHeader.jsp" />

			<jsp:include page="teacherMenu.jsp" />

			<!-- Sidebar Footer Content -->
			<jsp:include page="../common/sidebarFooter.jsp" />

		</div>

	</div>	
	<script type="text/javascript">
		$(function(){
			$("#subjectSettings").addClass("current_page_item");
		});
	</script>
	
	
	<script type="text/javascript">
	$(".submit_errors_msg").hide();
	$(".submit_errors").hide();
	
	function checkFormErrors(){
		if(isAnyFieldEmpty($('#elective_select'),$('#subject_name'),$('#teacher_select'))){
			return true;
		}
		return false;
	}
	
	<!-- Email, Name and Password Validation Function Call in validate.js -->
		$("#student_email").keyup(function() {
			isEmailValid($("#student_email"));
		});	
		$("#student_fname").keyup(function() {
			isNameValid($("#student_fname"));
		});
		$("#student_mobile").keyup(function() {
			isMobileValid($("#student_mobile"));
		});
		
		
		// Get Dropdown list values
		/* $("#sem_year_select").change(function(){
			var sem_name = $("#sem_year_select :selected").val();
			$("#sem_name_selected").val(sem_name);
		});	 */
		
		
		/* $("#teacher_select").change(function(){
			var teacher_name = $("#teacher_select :selected").val();
			$('#teacher_name_selected').attr("value",teacher_name);
			
		});	 */
		$("#elective_select").change(function(){
			var teacher_name = $("#elective_select").val();
			$('#elective_selected').attr("value",teacher_name);
			console.log(teacher_name);
			
		});	
		
	</script>
	</body>
</html>